import { Controller, Get, Post,Put, Body, Patch,Query, Param, Delete, Headers } from '@nestjs/common';
import { PromptService } from './prompt.service';
import { ApiTags } from '@nestjs/swagger';
import {PromptDto} from './dto/prompt.dto'
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('Prompt公共配置')
@Controller('prompt')
@isNoAuth()
export class PromptController {
  constructor(private readonly promptService: PromptService) {}

  @Post("add")
  create(@Headers() header,@Body() createPromptDto: PromptDto) {
    const dto = {...createPromptDto, userId: header.userid, time: (new Date().getTime()).toString() }
    return this.promptService.create(dto);
  }

  @Get("search")
  async findOne(@Query() query):Promise<PromptDto[]> {
    return  await this.promptService.findOne(query.title, query.id);
  }

  @Put('update/:id')
  update(@Param() param, @Body() updatePromptDto: PromptDto) {
    return this.promptService.update(param.id, updatePromptDto);
  }

  @Delete('del')
  remove(@Query() query):Promise<string> {
    return this.promptService.remove(query.id);
  }

  @Get('list')
  list(@Headers() header, @Query() query):Promise<any> {
    return this.promptService.list(query.page,query.pageSize,header.userid);
  }
}
